#include "../ServiceImp_h/LoginImp.h"
#include "../DataBase_h/DataBaseManager.h"
#include "DataBase_h/DataTableConfig.h"
#include "../Entity_h/user.h"
#include "../Error_h/error.h"
#include <QDebug>

LoginImp::LoginImp(UserTable& userTable){
    _userTable = &userTable;

}

int LoginImp::CheckUser(User& user) {
    int isConnect = _dataBaseManager->Connect();
    //connect succeed
    if(isConnect == NONE){

        QString userId = user.GetUserInfo().userId;
        QString userPwd = user.GetUserInfo().userPwd;

        return _dataBaseManager->CheckUser(userId, userPwd, *_userTable);

    }

    //connect failed
    else{
        return DATABASE_CONNECT_ERROR;
        qDebug()<<"error code:" << isConnect <<"error info"<< DATABASE_CONNECT_ERROR;
    }
}
